﻿using System;
using System.Collections.Generic;
using System.Text;
using LLFM.CAT.Config;
using Common;
using System.Data;
using System.Data.SqlClient;
using LLFM.CAT.Model;


namespace LLFM.CAT.Service
{
    public sealed class SeriesImagesService
    {
        /// <summary>
        /// 得到系列图片列表
        /// </summary>
        /// <param name="seriesId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static List<M_SeriesImages> GetSeriesImagesList(int seriesId, int status)
        {
            DataTable dt = SqlHelper.ExecuteDataset(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_GetSeriesImagesList"
                , new SqlParameter("@SeriesId", seriesId)
                , new SqlParameter("@Status", status)).Tables[0];
            return ModelHelper.FillModelsFromDataTable<M_SeriesImages>(dt);
        }

        public static void CreateSeriesImages(string imgUrl, string name, int seriesId, int sequence, short status)
        {
            SqlHelper.ExecuteNonQuery(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_CreateSeriesImages"
                , new SqlParameter("@ImageUrl", imgUrl)
                , new SqlParameter("@Name", name)
                , new SqlParameter("@SeriesId", seriesId)
                , new SqlParameter("@Status", status)
                , new SqlParameter("@Sequence", sequence));
        }

        public static void DelImgs(List<M_SeriesImages> delImgs)
        {
            StringBuilder sql = new StringBuilder();
            foreach (M_SeriesImages img in delImgs)
            {
                sql.Append(string.Format("exec pro_UpdateSeriesImageStatusById {0},{1};", img.Id,0));
            }
            if (sql.ToString() != string.Empty)
            {
                SqlHelper.ExecuteNonQuery(DBConfig.BitautoSDT, CommandType.Text, sql.ToString());
            }
        }

        public static void DelseriesImagById(int id)
        {
            SqlHelper.ExecuteNonQuery(
               DBConfig.BitautoSDT,
               CommandType.StoredProcedure,
               "pro_UpdateSeriesImageStatusById",
               new SqlParameter("@Id", id)
               );
        }
    }
}
